//
//  ZWKeyboardToolbar.swift
//  ZWWeibo
//
//  Created by flyiron on 16/4/28.
//  Copyright © 2016年 flyiron. All rights reserved.
//

import UIKit
enum ZWKeyboardToolbarType: Int {
    case Recent = 0 , Default, Emoji, Lxh
}
class ZWKeyboardToolbar: UIStackView {
    var keyboardClosure:((type:ZWKeyboardToolbarType)->())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        distribution = .FillEqually
        addButton("compose_emotion_table_left", title: "最近",type:.Recent)
        addButton("compose_emotion_table_mid", title: "默认",type:.Default)
        addButton("compose_emotion_table_mid", title: "emoji",type:.Emoji)
        addButton("compose_emotion_table_right", title: "钱浪",type:.Lxh)
    }
    
    @objc private func clickButton(sender:UIButton){
        keyboardClosure!(type:ZWKeyboardToolbarType(rawValue: sender.tag)!)
        
    }
    private func addButton(imageNamed: String,title:String,type:ZWKeyboardToolbarType){
        let button = UIButton(textColor: UIColor.darkGrayColor(), fontSize: 14)
        button.tag = type.rawValue
        button.addTarget(self, action: #selector(ZWKeyboardToolbar.clickButton(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        button.setTitle(title, forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "\(imageNamed)_normal"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "\(imageNamed)_selected"), forState: UIControlState.Selected)
        addArrangedSubview(button)
    }
}
